﻿using System.Runtime.InteropServices;


namespace 大漠收费版注册
{
    internal class Program
    {
        [DllImport("DmReg.dll")]
        public static extern int SetDllPathA(string path, int mode);



        static void Main(string[] args)
        {
            Console.WriteLine("Hello, World!");
            for (int i = 5; i > 0; i--)
            {
                Console.WriteLine($"开始倒计时{i}");
                Thread.Sleep(1000);
            }
            var dm_ret = SetDllPathA("dm.dll", 1);
            dmsoft dm = new dmsoft();



            Console.WriteLine(dm.Ver());
            var dmReg = dm.Reg("xys25459573b0e03d60b0c2fd8f4f51454be259d10", "");
            if (dmReg == 1)
            {
                Console.WriteLine("大漠收费版注册成功");
            }
            else
            {
                Console.WriteLine($"注册失败,错误代码{dmReg}");
                Console.Read();
                return;
            }

            

            var dmai = dm.LoadAi("ai.module");
            switch (dmai)
            {
                case 1:
                    Console.WriteLine("AI载块:加载AI模块成功");
                    break;
                case -1:
                    Console.WriteLine("AI载块:打开文件失败");
                    break;
                case -2:
                    Console.WriteLine("AI载块:打开文件失败");
                    break;
                case -3:
                    Console.WriteLine("AI载块:参数错误");
                    break;
                case -4:
                    Console.WriteLine("AI载块:加载错误");
                    break;
                case -5:
                    Console.WriteLine("Ai模块初始化失败");
                    break;
                case -6:
                    Console.WriteLine("AI载块:内存分配失败");
                    break;


                default:
                    Console.WriteLine("AI载块:未知错误");
                    break;
            }


            if (dm.AiYoloSetVersion("v5-7.0") == 1)
            {
                Console.WriteLine("Yolo的版本信息为:v5-7.0");
            }
            else
            {
                Console.WriteLine("Yolo的版本信息设置失败");
                return;

            }

            int hwnd = dm.FindWindow("", "无尽冬日");
            int dm_bind = dm.BindWindow(hwnd, "normal", "windows", "windows", 0);

            if (dm_bind == 0)
            {
                Console.WriteLine("绑定失败，程序结束");
                Console.Read();
                return;
            }
            int x, y;
            dm.GetClientSize(hwnd, out x, out y);
            Console.WriteLine($"无尽冬日窗口的宽为:{x}，高为:{y}");


            while (dm.AiFindPic(0, 0, x, y, "全部帮助.bmp", 0.4, 1, out x, out y) == -1)
            {
                Thread.Sleep(1000);
                dm.GetClientSize(hwnd, out x, out y);  //初始化x,y
                Console.WriteLine($"没有找到互助按钮，延迟一秒后继续，宽和为:{x},{y}");

            }




            if (dm.SetWindowText(hwnd, "已绑定") != 1)
            {
                Console.WriteLine("变更标题失败");
            }

            Console.WriteLine($"找到互助按钮:{x}，高为:{y}");
            dm.UnBindWindow();
            dm_bind = 0;
            // dm_bind = dm.BindWindow(hwnd, "gdi", "dx.mouse.position.lock.api|dx.mouse.position.lock.message|dx.mouse.clip.lock.api|dx.mouse.input.lock.api|dx.mouse.state.api|dx.mouse.api|dx.mouse.cursor", "windows", 0);
            dm_bind = dm.BindWindow(hwnd, "gdi", "dx.mouse.position.lock.api|dx.mouse.position.lock.message|dx.mouse.input.lock.api|dx.mouse.state.api|dx.mouse.api|dx.mouse.cursor", "windows", 0);
            if (dm_bind == 0)
            {
                Console.WriteLine("后台绑定失败，程序结束");
                Console.Read();
                return;
            }

            dm.MoveTo(x, y);
            while (true)
            {
                dm.LeftClick();
                Thread.Sleep(200);
                Console.WriteLine("点击中...");
            }

            dm.UnBindWindow();
            dm.ReleaseObj();

            return;







            //绑定  无尽冬日
            //   int hwnd = dm.FindWindow("", "无尽冬日");
            //int dm_bind = dm.BindWindow(hwnd, "gdi", "dx.mouse.position.lock.api|dx.mouse.position.lock.message|dx.mouse.clip.lock.api|dx.mouse.input.lock.api|dx.mouse.state.api|dx.mouse.api|dx.mouse.cursor", "windows", 0);

            if (hwnd == 0)
            {
                Console.WriteLine("绑定失败，程序结束");
                Console.Read();
                return;
            }
            while (true)
            {
                dm.LeftClick();
                Thread.Sleep(200);
                Console.WriteLine("点击中...");
            }


            Console.WriteLine("结束");

            Console.Read();
        }


    }

}